import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController, Platform, App } from 'ionic-angular';
import { BusiProvider } from '../../providers/busi/busi';
import { NativeProvider } from '../../providers/native/native';
import { Global } from '../../common/global';

/**
 * Generated class for the MyPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-my',
  templateUrl: 'my.html',
})
export class MyPage {
  xm:string;
  username:string;
  userInfo:any;
  version:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,private busi:BusiProvider,private native:NativeProvider,
    public alertCtrl: AlertController,public platform: Platform,public appCtrl: App) {
    this.getCurrentUserDetail();
    this.native.getVersionNumber().then(
      data=>{
        this.version = data;
      }
    );
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad MyPage');
  }

  getCurrentUserDetail(){
    this.busi.getCurrentUserDetail().subscribe(
      data=>{
        this.userInfo = data.userdetail;
        this.xm = this.userInfo.xm;
        this.username = this.userInfo.username;
      },
      err=>{

      }
    )
  }

  edit(){
    this.navCtrl.push("UsereditPage");
  }

  exitSoftware() {
    this.alertCtrl.create({
      title: '确认退出软件？',
      buttons: [{text: '取消'},
        {
          text: '确定',
          handler: () => {
            this.platform.exitApp();
          }
        }
      ]
    }).present();
  }
  passwordchange(){
    this.navCtrl.push("PasswordchangePage");
  }
  loginOut(){
    localStorage.removeItem(Global.token);
    this.appCtrl.getRootNav().setRoot("RoleselectPage");
  }

}
